﻿// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_SALES_ORDER_TO_APP
// * CreateDate    : 2013/1/28 16:56:48
// * Creater       : SalesOrderToAppBs
// * LastChangeDate: 2013/1/28 16:56:48
// * LastChanger   : 2013/1/28 16:56:48
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Sales
{
    /// <summary>
    /// SalesOrderToApp
    /// </summary>
    public partial class SalesOrderToAppBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objSalesOrderToAppEntity">Entity</param>
        /// <returns>Entity</returns>
        public static SalesOrderToAppEntity GetSalesOrderToApp(SalesOrderToAppEntity objSalesOrderToAppEntity)
        {
            return DataAccess.SelectSingle<SalesOrderToAppEntity>(objSalesOrderToAppEntity);
        }
        public static DataTable GetDtByOrderId(string orderId)
        {
            string sql = @"SELECT * FROM dbo.SALES_ORDER_TO_APP WHERE SALES_ORDER_ID='"+orderId+"'";
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds == null || ds.Tables[0].Rows.Count == 0)
            {
                return null;
            }
            return ds.Tables[0];
        }
        public static DataTable GetDtByAppId(string appId)
        {
            string sql = @"SELECT * FROM SALES_ORDER_TO_APP WHERE APPLICATION_ID='" + appId + "'";
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds == null || ds.Tables[0].Rows.Count == 0)
            {
                return null;
            }
            return ds.Tables[0];
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objSalesOrderToAppEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertSalesOrderToApp(SalesOrderToAppEntity objSalesOrderToAppEntity)
        {
            return DataAccess.Insert(objSalesOrderToAppEntity);
        }

        public static bool InsertSalesOrderToApp(List<SalesOrderToAppEntity> objSalesOrderToAppEntityList)
        {
            return DataAccess.Insert(objSalesOrderToAppEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objSalesOrderToAppEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateSalesOrderToApp(SalesOrderToAppEntity objSalesOrderToAppEntity)
        {
            return DataAccess.Update(objSalesOrderToAppEntity);
        }

        public static bool UpdateSalesOrderToApp(List<SalesOrderToAppEntity> objSalesOrderToAppEntityList)
        {
            return DataAccess.Update<SalesOrderToAppEntity>(objSalesOrderToAppEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objSalesOrderToAppEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteSalesOrderToApp(SalesOrderToAppEntity objSalesOrderToAppEntity)
        {
            return DataAccess.Delete(objSalesOrderToAppEntity);
        }

        public static bool DeleteSalesOrderToApp(List<SalesOrderToAppEntity> objSalesOrderToAppEntityList)
        {
            return DataAccess.Delete<SalesOrderToAppEntity>(objSalesOrderToAppEntityList);
        }
        public static bool DeleteSalesOrderToApp(List<SalesOrderToAppEntity> objSalesOrderToAppEntityList, DataAccessBroker broker)
        {
            foreach (SalesOrderToAppEntity entity in objSalesOrderToAppEntityList)
            {
                string sql = @"DELETE FROM dbo.SALES_ORDER_TO_APP WHERE SALES_ORDER_ID='"+entity.SalesOrderId+"' AND APPLICATION_ID='"+entity.ApplicationId+"'";
                int i = broker.ExecuteSQL(sql);
                if (i != 1)
                {
                    return false;
                }
            }
            return true;
        }
        
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetSalesOrderToAppAll()
        {
            return DataAccess.SelectAllDataSet<SalesOrderToAppEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<SalesOrderToAppEntity> GetSalesOrderToAppAllList()
        {
            return DataAccess.SelectAll<SalesOrderToAppEntity>();
        }
        #endregion
    }


}

